package com.zhoushihao.class0807;

public class MyMath{
    public static int getMinPublic(int a,int b) {
        int max = Math.max(a,b);
        while(true){
            if(max % a == 0 && max % b == 0){
                return max;
            }
            max++;
        }
    }
    public static int getMaxPublic(int a,int b) {
        int min = Math.min(a,b);
        for (int i = min; i > 0; i--) {
            if(a % i == 0 && b % i == 0){
                return i;
            }
        }
        return 1;
    }
    public static double pow(int a,int b) {
        double result = 1;
        if(b == 0)return result;
        else if(b > 0){
//            for (int i = 0; i < b; i++) result *= a;
            result = a*pow(a,b-1);
        }
        else{
            if(a == 0) return Double.POSITIVE_INFINITY;
//            for (int i = 0; i < -b; i++) result /= a;
            result = pow(a,b+1) / a;
        }
        return result;
    }
    public static int factorial(int n) {
        int result = 1;
        if(n == 0)return result;
        for (int i = 1; i <= n; i++) {
            result *= i;
        }
        return result;
    }
}
